package servlet;

import service.OrdersService;
import service.impl.OrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        //定义session对象
        HttpSession session = request.getSession();
        //创建Writer对象
        PrintWriter out = response.getWriter();
        String opr = request.getParameter("opr");

        if(opr.equals("delivery")){
            //查询id
            int id = Integer.parseInt(request.getParameter("id"));
            OrdersService service=new OrdersServiceImpl();
            int update = service.update(id);
            if(update>0){
                out.print(true);
            }else {
                out.print(false);
            }
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
